package com.example.mymatch.controller;

import com.example.mymatch.model.Leave;
import com.example.mymatch.service.ILeaveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * LeaveController层
 * 编写者：杨滢
 */

@Api(tags = "请假")
@RestController
public class LeaveController {
    @Autowired
    private ILeaveService leaveService;//对某个业务服务的内容进行定义规范  编写者：杨滢

    @ApiOperation(value = "查询所有请假信息",notes = "获取请假信息返回json字符串")
    @RequestMapping("/getStr13")
    public String getLeave(){
        return "My leave";
    }
    @CrossOrigin
    @ApiOperation(value = "对请假信息的添加方法")
    @GetMapping("/addLeave")
    public int addLeave(Leave leave){
        System.out.println("进入添加请假信息接口");
        return leaveService.insertLeave(leave);
    }

    @GetMapping("getAll13")
    @ApiOperation(value = "对请假信息的查询方法")
    public List<Leave> getAllLeave(Leave leave){
        System.out.println("进入查询方法");

        List<Leave> listLeave=leaveService.getAllLeave(leave);

        return listLeave;
    }

    @PutMapping("/editLeave")
    @ApiOperation(value = "对请假信息的修改方法")
    public int EditLeave(@RequestBody Leave leave){
        System.out.println("进入请假修改方法");
        return leaveService.updateLeave(leave);
    }

    @GetMapping("/delLeave")
    @ApiOperation(value = "对请假信息的删除方法")
    public int Delete(int id){
        System.out.println("进入请假删除方法");
        int returnValue=0;
        if (id!=0){
            Leave leave=new Leave();
            leave.setId(id);
            returnValue= leaveService.deleteLeave(leave);
        }
        return returnValue;
    }

    @GetMapping("/getOne13")
    @ApiOperation(value = "对单条请假信息的查询方法")
    public  Leave getLeave(int id){
        Leave leave=new Leave();
        System.out.println("进入请假查询方法");
        if (id!=0){
            Leave leave1=new Leave();
            leave1.setId(id);
            leave=leaveService.getLeave(leave1);
            System.out.println("返回的数据集合为："+leave.getLeaveName());
        }
        return leave;
    }
}
